package io.yizoo.business.controller;

import io.yizoo.business.entity.biz_hrm_ei_basic;
import io.yizoo.business.entity.biz_wms_goods;
import io.yizoo.business.entity.biz_wms_goods_type;
import io.yizoo.business.entity.biz_wms_material_adjust;
import io.elm.core.CoreController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/business/wms/material_adjust")
public class wms_material_adjustController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity = biz_wms_material_adjust.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("t.*,ifnull(a.name,t.material_name) as material_name_mc,ifnull(b.type,t.material_category) as material_category_mc,ifnull(c.name,t.update_role) as update_role_mc")
                        .From(biz_wms_material_adjust.class,"t")
                        .LeftJoin(biz_wms_goods.class,"a","a.sys_code_key=t.material_name")
                        .LeftJoin(biz_wms_goods_type.class,"b","b.id=t.material_category")
                        .LeftJoin(biz_hrm_ei_basic.class,"c","c.emp_code=t.update_role")
                        .IsWhere("and a.name like concat('%', #{name}, '%')", "name")
                        .IsWhere("and material_name = #{id}","id")
                        .OrderBy("update_time desc")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

}